package cn.mastercom.gui.hdfsExplorer.views;

import cn.mastercom.gui.components.CustomDialog;
import cn.mastercom.sssvr.util.HdfsExplorerHelper;
import cn.mastercom.sssvr.util.HdfsExplorerHelper.GotoPathCmd;
import lombok.extern.log4j.Log4j;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.Path;
import org.apache.log4j.Logger;

import javax.swing.*;
import javax.swing.border.EmptyBorder;
import javax.swing.event.TreeExpansionEvent;
import javax.swing.event.TreeExpansionListener;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.TreePath;
import java.awt.*;
import java.awt.datatransfer.StringSelection;
import java.awt.event.*;
import java.io.File;
import java.util.*;
import java.util.List;

@Log4j
public class TreePane extends JScrollPane implements Observer {

	private static final long serialVersionUID = 1L;

	private JTree tree;
	private DefaultMutableTreeNode treeRoot;
	private DefaultMutableTreeNode currentSelectedNode;
	private transient HdfsExplorerHelper helper;
	private JPopupMenu popup;

	public TreePane(HdfsExplorerHelper helper) {
		this.tree = new JTree(new DefaultMutableTreeNode(helper.getHdfsAddr()+"/"));
		this.helper = helper;
		this.treeRoot = (DefaultMutableTreeNode) tree.getModel().getRoot();
		this.currentSelectedNode = treeRoot;
		helper.addObserver(this);

		initUI();
		initLookAndFeel();
		addEventListener();
		addActionListener();
	}

	private void initLookAndFeel() {
		helper.initLookAndFeel();
	}

	private void initUI() {
		DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer() {
			private static final long serialVersionUID = 1L;

			@Override
			public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded,
					boolean leaf, int row, boolean hasFocus) {
				super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
				if (value instanceof DefaultMutableTreeNode) {
					DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
					Object object = node.getUserObject();
					if (object instanceof FileStatus) {
						this.setText(((FileStatus) object).getPath().getName());
					}
				}
				if (leaf) {
					Icon icon;
					String str = value.toString();
					if (str.indexOf('.') == 0 || str.equals("")) {
						icon = new ImageIcon("images/nullNode.gif");
					} else {
						icon = helper.getSystemIcon(value.toString(), false);
					}
					this.setIcon(icon);
				}
				return this;
			}
		};
		renderer.setLeafIcon(helper.getSystemIcon(null, true));
		renderer.setOpenIcon(helper.getSystemIcon(null, true));
		tree.setCellRenderer(renderer);

		treeRoot.add(new DefaultMutableTreeNode("."));

		setViewportView(tree);
	}

	private void addEventListener() {
		tree.addTreeExpansionListener(new TreeExpansionListener() {
			@Override
			public void treeCollapsed(TreeExpansionEvent e) {
				TreePath path = e.getPath();
				if (path == null)
					return;
				DefaultMutableTreeNode selectnode = (DefaultMutableTreeNode) path.getLastPathComponent();
				if (selectnode == treeRoot)
					return;
				if (selectnode.getChildCount() > 1) {
					for (int i = selectnode.getChildCount() - 1; i >= 0; i--) {
						TreePath pathChild = new TreePath(selectnode.getChildAt(i));
						DefaultMutableTreeNode childnode = (DefaultMutableTreeNode) pathChild.getLastPathComponent();
						if (childnode.getUserObject() instanceof FileStatus) {
							FileStatus file = (FileStatus) childnode.getUserObject();
							if (file != null)
								selectnode.remove(i);
						}
					}
				}
				addNullNode(selectnode);// 关闭树后增加一个空节点
			}

			@Override
			public void treeExpanded(TreeExpansionEvent e) {
				tree.setSelectionPath(e.getPath());
				TreePath path = tree.getSelectionPath();
				if (path == null)
					return;

				DefaultMutableTreeNode selectnode = (DefaultMutableTreeNode) path.getLastPathComponent();

				String targetPath;
				if (selectnode != treeRoot)
					targetPath = ((FileStatus) selectnode.getUserObject()).getPath().toString();
				else
					targetPath = treeRoot.getUserObject().toString();

				currentSelectedNode = selectnode;
				helper.executeCmd(new GotoPathCmd(targetPath, helper));
				//helper.executeCmd(new GotoPathCmd(targetPath, helper));
			}
		});

        // 添加listener
        tree.addTreeSelectionListener(e -> {

        });

		tree.addMouseListener(new MouseAdapter() {
			@Override
			public void mousePressed(MouseEvent e) {
				TreePath path = tree.getPathForLocation(e.getX(), e.getY());
				tree.setSelectionPath(path);
			}
		});

		tree.addKeyListener(new KeyAdapter() {
			@Override
			public void keyPressed(KeyEvent e) {
				if (e.isControlDown() && e.isShiftDown() && e.getKeyCode() == 'C') {
					copyFile();
				}
				if (e.isControlDown() && e.isShiftDown() && e.getKeyCode() == 'V') {
					copyToHdfs();
				}
				if (e.isControlDown() && e.isShiftDown() && e.getKeyCode() == 'X') {
					moveFile();
				}
				if (e.isControlDown() && e.getKeyCode() == 'D') {
					deleteFile();
				}
			}
		});
	}

	private void addActionListener() {
		// 从HDFS下载
		popup = new JPopupMenu();
		JMenuItem menuItem = new JMenuItem("从HDFS下载...");
		final JFileChooser fileChooser = new JFileChooser();
		menuItem.addActionListener(e -> {
            final FileStatus theFile = getSelectedFileStatus();
            if (theFile == null)
                return;
            final String hdfsPath = theFile.getPath().toString();
            fileChooser.setDialogTitle("请选择目的文件夹");
            fileChooser.setApproveButtonText("确定");
            fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            int result = fileChooser.showOpenDialog(null);
            if (JFileChooser.APPROVE_OPTION == result) {
                final String localPath = fileChooser.getSelectedFile().getPath();
                if (theFile.isDirectory()) {
                    helper.downDir(hdfsPath, localPath);
                } else
                    helper.downFile(hdfsPath, localPath);
            }
        });
		popup.add(menuItem);

		menuItem = new JMenuItem("归并压缩下载");
		menuItem.addActionListener(e -> {
            FileStatus theFile = getSelectedFileStatus();
            if (theFile == null)
                return;

            final String hdfsPath = theFile.getPath().toString();
            final String hdfsFileName = theFile.getPath().getName().toString();
            boolean isDir = theFile.isDirectory();

            fileChooser.setDialogTitle("请选择目的文件夹");
            fileChooser.setApproveButtonText("确定");
            fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            int result = fileChooser.showOpenDialog(null);

            if (JFileChooser.APPROVE_OPTION == result) {
                final String localPath = fileChooser.getSelectedFile().getPath();
                if (isDir) {
                    helper.mergeDown(hdfsPath, localPath + "/" + hdfsFileName);
                } else {
                    CustomDialog.show("只有文件夹才需要归并压缩下载！");
                }
            }
        });
		
		
		popup.add(menuItem);
		// 新建文件夹
		menuItem = new JMenuItem("新建文件夹...");
		menuItem.addActionListener(e -> {
            createNewDir();
            expandSpecialPath(tree.getSelectionPath());
        });
		
		
		popup.add(menuItem);
		// 上传文件
		menuItem = new JMenuItem("上传文件...");
		menuItem.addActionListener(e -> {
            final FileStatus theFile = getSelectedFileStatus();
            if (theFile == null)
                return;
            fileChooser.setDialogTitle("请选择要上传的文件");
            fileChooser.setApproveButtonText("确定");
            fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
            fileChooser.setMultiSelectionEnabled(true);
            int result = fileChooser.showOpenDialog(null);
            if (JFileChooser.APPROVE_OPTION == result) {
                final File[] files = fileChooser.getSelectedFiles();
                for (final File file : files) {
                    if (file.isFile()) {
                        helper.uploadFile(file.getPath().toString(), theFile.getPath().toString());
                    }
                }
            }
        });
		popup.add(menuItem);
		// 解压上传文件
		menuItem = new JMenuItem("解压上传文件...");
		menuItem.addActionListener(e -> {
            final FileStatus theFile = getSelectedFileStatus();
            if (theFile == null)
                return;
            fileChooser.setDialogTitle("请选择要上传的文件");
            fileChooser.setApproveButtonText("确定");
            fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
            fileChooser.setMultiSelectionEnabled(true);

            int result = fileChooser.showOpenDialog(null);
            if (JFileChooser.APPROVE_OPTION == result) {
                File[] files = fileChooser.getSelectedFiles();

                for (final File file : files) {
                    if (file.isFile()) {
                        helper.uncompressUpload(file.getPath().toString(), theFile.getPath().toString());
                    }
                }
            }
        });
		popup.add(menuItem);
		// 上传文件夹
		menuItem = new JMenuItem("上传文件夹...");
		menuItem.addActionListener(e -> {
            final FileStatus theFile = getSelectedFileStatus();
            if (theFile == null)
                return;

            fileChooser.setDialogTitle("请选择要上传的目录");
            fileChooser.setApproveButtonText("确定");
            fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            fileChooser.setMultiSelectionEnabled(true);

            int result = fileChooser.showOpenDialog(null);
            if (JFileChooser.APPROVE_OPTION == result) {
                final File[] files = fileChooser.getSelectedFiles();

                for (File file : files) {
                    if (file.isDirectory())
                        helper.uploadDir(file.getPath().toString(),
                                theFile.getPath().toString() + "/" + file.getName());
                }
            }
        });
		popup.add(menuItem);
		// 归并上传文件夹
		menuItem = new JMenuItem("归并上传文件夹...");
		menuItem.addActionListener(e -> {
            final FileStatus theFile = getSelectedFileStatus();
            if (theFile == null)
                return;

            fileChooser.setDialogTitle("请选择要上传的目录");
            fileChooser.setApproveButtonText("确定");
            fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            fileChooser.setMultiSelectionEnabled(true);

            int result = fileChooser.showOpenDialog(null);
            if (JFileChooser.APPROVE_OPTION == result) {
                final File file = fileChooser.getSelectedFile();
                helper.mergeUpload(file.getPath().toString(), theFile.getPath().toString(), file.getName());
            }
        });
		popup.add(menuItem);

		// 添加SUCCESS标志文件
		menuItem = new JMenuItem("添加SUCCESS标志文件");
		menuItem.addActionListener(e -> {
            FileStatus theFile = getSelectedFileStatus();
            helper.createSuccessFile(theFile.getPath().toString());
            expandSpecialPath(tree.getSelectionPath());
        });
		popup.add(menuItem);
		// 分割符
		popup.addSeparator();
        menuItem = new JMenuItem("合并小文件");
        menuItem.addActionListener(e -> {
            FileStatus theFile = getSelectedFileStatus();
            FileStatus[] files = helper.listStatus(theFile.getPath().toString());
            if (files.length < 2) return;
            helper.concat(files);
        });
        popup.add(menuItem);
		popup.addSeparator();
		// 删除
		menuItem = new JMenuItem("删除");
		menuItem.addActionListener(e -> {
            TreePath path = tree.getSelectionPath().getParentPath();
            deleteFile();
            expandSpecialPath(path);
        });
		popup.add(menuItem);
		// 重命名
		menuItem = new JMenuItem("重命名");
		menuItem.addActionListener(e -> {
            FileStatus theFile = getSelectedFileStatus();
            String thePath = theFile.getPath().toString();
            String theFileName = theFile.getPath().getName();
            String thePathParent = theFile.getPath().getParent().toString();
            TreePath parentPath = tree.getSelectionPath().getParentPath();
            renameHdfsFile(thePath, theFileName, thePathParent);
            expandSpecialPath(parentPath);
        });
		popup.add(menuItem);

        // 过滤
        menuItem = new JMenuItem("过滤");
        menuItem.addActionListener(e -> {
            FileStatus theFile = getSelectedFileStatus();
            String thePath = theFile.getPath().toString();
            String theFileName = theFile.getPath().getName();
            String thePathParent = theFile.getPath().getParent().toString();
            TreePath parentPath = tree.getSelectionPath().getParentPath();
            filterHdfsFile(thePath, theFileName, thePathParent);
            expandSpecialPath(parentPath);
        });
        popup.add(menuItem);

		// 赋权777
		menuItem = new JMenuItem("赋权777");
		menuItem.addActionListener(e -> {
            FileStatus theFile = getSelectedFileStatus();
            helper.chmod(theFile);
        });
		popup.add(menuItem);
		
		// 剪切
		menuItem = new JMenuItem("剪切");
		menuItem.addActionListener(e -> moveFile());
		popup.add(menuItem);

		// 复制
		menuItem = new JMenuItem("复制");
		menuItem.addActionListener(e -> copyFile());
		popup.add(menuItem);
		// 粘贴
		menuItem = new JMenuItem("粘贴");
		menuItem.addActionListener(e -> copyToHdfs());
		popup.add(menuItem);
		// 分割符
		popup.addSeparator();
		// 复制完整名称
				menuItem = new JMenuItem("复制完整名称");
				menuItem.addActionListener(e -> {
                    FileStatus theFile = getSelectedFileStatus();
                    Toolkit.getDefaultToolkit().getSystemClipboard()
                            .setContents(new StringSelection(theFile.getPath().toString()), null);
                });
				popup.add(menuItem);	
				
				
		tree.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseReleased(final MouseEvent e) {
				if (e.isPopupTrigger()) {
					popup.show(e.getComponent(), e.getX(), e.getY());
				}
			}
		});
	}

	@Override
	public void update(Observable o, Object arg) {
		if (o instanceof HdfsExplorerHelper) {
			if (arg instanceof String) {
				// 当前选中的节点与传进来的节点不一致的话，就不能添加 treeNode 到当前节点
				if (currentSelectedNode == treeRoot) {
					if (!currentSelectedNode.toString().equals(arg)) {
						return;
					}
				}
				if (currentSelectedNode.getUserObject() instanceof FileStatus) {
					FileStatus fStatus = (FileStatus)currentSelectedNode.getUserObject();
					if (!fStatus.getPath().toString().equals(arg.toString())) {
						return;
					}
				}
				FileStatus[] fileStatus = ((HdfsExplorerHelper) o).listStatus((String) arg);
				refreshTree(fileStatus, currentSelectedNode);
				SwingUtilities.invokeLater(new Runnable() {
					@Override
					public void run() {
						tree.updateUI();
					}
				});
			}
		}
	}

	/**
	 * 渲染某个JTreeNode下的子节点信息
	 */
	private void refreshTree(FileStatus[] list, DefaultMutableTreeNode node) {
		if (list == null || node == null)
			return;

		node.removeAllChildren();
		node.add(new DefaultMutableTreeNode("."));
		for (int i = list.length - 1; i >= 0; i--) {

			FileStatus file_inlist = list[i];
			// String filename = file_inlist.getName();

			if (file_inlist.isDirectory()) {
				DefaultMutableTreeNode subNode = new DefaultMutableTreeNode(file_inlist);
				// 添加空白文件夹节点 使子节点显示为文件夹
				subNode.add(new DefaultMutableTreeNode("."));
				// 计算所有文件夹大小
				subNode.setUserObject(list[i]);
				node.add(subNode);
			} else {
				// 不添加文件作为子节点
				// DefaultMutableTreeNode son = new DefaultMutableTreeNode(new
				// MyFile(file_inlist));
				// node.add(son);
			}
		}

		// 删除原有的空节点
		if (currentSelectedNode.getChildCount() > 1)
			removeFirstChildNode(currentSelectedNode);
	}

	/**
	 * 从JTree上获取文件状态信息
	 */
	private FileStatus getSelectedFileStatus() {
		TreePath path = tree.getSelectionPath();
		if (path == null)
			return null;

		DefaultMutableTreeNode selectnode = (DefaultMutableTreeNode) path.getLastPathComponent();
		if (selectnode == treeRoot) {
			return new FileStatus(0, true, 0, 0, 0, 0, null, null, null, new Path("/"));
		}
		// 这里加上类型判断
		if (!(selectnode.getUserObject() instanceof FileStatus)) {
			return null;
		}
		FileStatus file_select = (FileStatus) selectnode.getUserObject();
		// log.info(file_select.getPath());
		return file_select;
	}

	/**
	 * 复制文件
	 */
	private void copyFile() {
		FileStatus theFile = getSelectedFileStatus();
		if (theFile != null) {
		Toolkit.getDefaultToolkit().getSystemClipboard()
				.setContents(new StringSelection("cp" + theFile.getPath().toString() + "\n"), null);
	
		}
		 
	}
	/**
	 * 粘贴文件
	 */
	private void copyToHdfs() {
		FileStatus theFile = getSelectedFileStatus();
		if (theFile != null) {
		helper.pasteFile(theFile.getPath().toString());
		TreePath path = tree.getSelectionPath();
		expandSpecialPath(path);
		}
	}
	/**
	 * 剪切文件
	 */
	private void moveFile() {
		FileStatus theFile = getSelectedFileStatus();
		if(theFile != null){
		Toolkit.getDefaultToolkit().getSystemClipboard()
				.setContents(new StringSelection("mv" + theFile.getPath().toString() + "\n"), null);
		}
	}
	/**
	 * 删除文件
	 */
	private void deleteFile() {
		FileStatus theFile = getSelectedFileStatus();
		if (theFile != null) {
		int n = JOptionPane.showConfirmDialog(null, "确认删除" + theFile.getPath() + "吗？", "确认删除框",
				JOptionPane.YES_NO_OPTION);
		if (n == JOptionPane.NO_OPTION) {
			return;
		}
		
			String thePath = theFile.getPath().toString();
			try {
				helper.deleteFile(thePath);
			} catch (Exception e1) {
				log.info(thePath + "删除失败！！！");
			}
		}
	}

	/**
	 * tableModel没数据时，添加一行空行
	 */
	private void addNullNode(DefaultMutableTreeNode selectnode) {
		int nNum = selectnode.getChildCount();
		if (nNum < 1) {
			DefaultMutableTreeNode stub = new DefaultMutableTreeNode(".");
			selectnode.add(stub);
		}
	}

	/**
	 * 删除第一个节点
	 */
	private void removeFirstChildNode(DefaultMutableTreeNode selectnode) {
		DefaultMutableTreeNode firstchild = (DefaultMutableTreeNode) selectnode.getFirstChild();
		int nNum = selectnode.getChildCount();
		if (nNum > 1)
			selectnode.remove(firstchild);
	}

	// TODO ：这些将来都要删除
	private JTextField tfSubFoldName;
	private JTextField tfSubFoldName2;
	private JTextField tfSubFoldName3;
	private JTextField tfSubFoldName4;
	private JTextArea  textArea;
	private JComboBox  jcb;
	private String condition = null;
	private String dataType = null;
	private String dataPath = null;

	/**
	 * 重命名文件
	 */
	private void renameHdfsFile(String thePath, String theFileName, String thePathParent) throws HeadlessException {
		Object options[] = { "确定", "取消" };

		JPanel contentPanel = new JPanel();
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPanel.setLayout(null);

		JLabel label = new JLabel("请输入" + theFileName + "的新名称");
		label.setBounds(10, 23, 125, 15);
		contentPanel.add(label);

		JTextField tfSubFoldName = new JTextField();
		tfSubFoldName.setBounds(20, 48, 350, 21);
		contentPanel.add(tfSubFoldName);
		tfSubFoldName.setColumns(10);
		tfSubFoldName.setText(new Path(thePath).getName());
		contentPanel.setPreferredSize(new Dimension(100, 88));

		int answer = JOptionPane.showOptionDialog(null, contentPanel, "重命名",  JOptionPane.YES_NO_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[1]);
		if (answer == 0) {
			thePathParent = thePathParent.charAt(thePathParent.length() - 1) == '/' ? thePathParent
					: thePathParent + "/";
			helper.renameFile(thePath, thePathParent + tfSubFoldName.getText());
			helper.refresh();
		}
	}

	private void createNewDir() {
		FileStatus theFile = getSelectedFileStatus();
		if (theFile == null) {
			return;
		}
		if (!theFile.isDirectory())
			return;
		Object[] options = { "确定", "取消" };

		JPanel contentPanel = new JPanel();
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPanel.setLayout(null);

		JLabel label = new JLabel("请输入子目录的名称");
		label.setBounds(10, 23, 125, 15);
		contentPanel.add(label);

		tfSubFoldName = new JTextField();
		tfSubFoldName.setBounds(20, 48, 350, 21);
		contentPanel.add(tfSubFoldName);
		tfSubFoldName.setColumns(10);
		contentPanel.setPreferredSize(new Dimension(100, 88));
		if (label != null)
			label.setText("请输入子目录的名称");

		int answer = JOptionPane.showOptionDialog(null, contentPanel, "创建子目录", JOptionPane.YES_NO_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[1]);
		if (answer == 0) {
			helper.createDir(theFile.getPath().toString() + "/" + tfSubFoldName.getText().trim());
		}
	}

	/**
	 * 刷新选中的节点
	 */
	@SuppressWarnings("unused")
	private void refreshSelectedPath() {
		TreePath path = tree.getSelectionPath();
		refreshSpecialPath(path);
	}

	/**
	 * 刷新指定节点
	 */
	private void refreshSpecialPath(TreePath path) {
		if (path == null) {
			return;
		}
        currentSelectedNode = (DefaultMutableTreeNode) path.getLastPathComponent();
		Object object = currentSelectedNode.getUserObject();
		if (object instanceof FileStatus) {
			FileStatus fileStatus = (FileStatus) object;
			helper.refresh(fileStatus.getPath().toString());
		}
	}

	public void expandRootPath() {
		tree.expandPath(new TreePath(treeRoot));
	}
	
	/**
	 * 触发指定节点的展开事件
	 */
	private void expandSpecialPath(TreePath path) {
		if (tree.isExpanded(path))
			refreshSpecialPath(path);
		else
			tree.expandPath(path);
	}

	/**
	 * 过滤文件
	 */
	private void filterHdfsFile(String thePath, String theFileName, String thePathParent) throws HeadlessException {
		Object[] options = { "确定", "取消" };

		JPanel contentPanel = new JPanel();

		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPanel.setLayout(null);

		JLabel label = new JLabel("要过滤的路径：");
		label.setBounds(10, 30, 100, 15);
		contentPanel.add(label);

		JTextField tfSubFoldName = new JTextField();
		tfSubFoldName.setBounds(120, 25, 350, 21);
		contentPanel.add(tfSubFoldName);
		tfSubFoldName.setText(thePath);

		JLabel label2 = new JLabel("请输入分离符：");
		label2.setBounds(10, 80, 100, 15);
		contentPanel.add(label2);
		String str1[] = {"\\t",",","_"};
		jcb = new JComboBox(str1);
		jcb.setEditable(true);
		jcb.setBounds(120, 75, 350, 21);
		contentPanel.add(jcb);

		JLabel label3 = new JLabel("输入sql语句：");
		label3.setBounds(10, 130, 100, 15);
		contentPanel.add(label3);
		JTextArea textArea = new JTextArea();
		textArea.setBounds(120, 125, 350, 100);
		textArea.setLineWrap(true);
		contentPanel.add(textArea);
		textArea.setText("select * from tb_mt_" + theFileName);

		JLabel label4 = new JLabel("要输出的路径：");
		label4.setBounds(10, 255, 100, 15);
		contentPanel.add(label4);
		JTextField tfSubFoldName4 = new JTextField();
		tfSubFoldName4.setBounds(120,250, 350, 21);
		contentPanel.add(tfSubFoldName4);
		tfSubFoldName4.setColumns(10);

		contentPanel.setPreferredSize(new Dimension(500,300));

		int answer = JOptionPane.showOptionDialog(null, contentPanel, "过滤", 0, -1, null, options, options[1]);
		if (answer == 0) {
			helper.filterSpark(tfSubFoldName.getText(),jcb.getSelectedItem().toString(),textArea.getText(),tfSubFoldName4.getText());
			helper.refresh();
		}
	}
}
